package com.nuaa.dao.announcement.impl;

import java.util.Date;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.stereotype.Repository;
import com.nuaa.dao.announcement.inter.AnnounceDaoInter;
import com.nuaa.dao.base.impl.BaseDaoImpl;
import com.nuaa.domain.announcement.AnnounceEntity;
import com.nuaa.utils.AjaxMsg;
/***
 * 通告管理Dao
 * @author heaven
 *
 */
@Repository("announceDao")
public class AnnounceDaoImpl extends BaseDaoImpl<AnnounceEntity, Integer> implements AnnounceDaoInter{
	/**提交修改的通告*/
	@Override
	@Transactional
	public AjaxMsg subAnnounceInfo(AnnounceEntity entity) {
		int type = entity.getType();
		String judgeSql = "select * from announce_info where type="+String.valueOf(type);
		AjaxMsg msg = new AjaxMsg();
		try{
			List<AnnounceEntity> list = this.search(AnnounceEntity.class, judgeSql);
			if(list.size()==0){
				entity.setEdit_tm(new Date());
				this.save(entity);
			}else{
				list.get(0).setContent(entity.getContent());
				list.get(0).setEdit_tm(new Date());
			}
			msg.setMsg("提交成功！");
			msg.setSuccess(true);
		}catch(Exception e){
			msg.setMsg("提交失败！");
			msg.setSuccess(false);
		}
		return msg;
	}
	/**获取所有通告信息*/
	@Override
	public List<AnnounceEntity> getAllInfo(){
		String sql = "select * from announce_info ";
		return this.search(AnnounceEntity.class, sql);
	}
}
